package com.zl.learning.thread.completion_service;

import java.util.concurrent.*;

public class Test1 {
    public static void main(String[] args) {
        ExecutorService executor = Executors.newSingleThreadExecutor();
        UserInfo userInfo = new UserInfo();
        CompletionService<UserInfo> service = new ExecutorCompletionService<UserInfo>(executor);
        Future<UserInfo> futureTask = service.submit(()->{
            System.out.println("aaaaaa");
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            userInfo.setUserId(1);
            userInfo.setUsername("zhangsan");
        },userInfo);
        System.out.println("bbbbb");
        try {
            futureTask.get();
            System.out.println(userInfo);
            executor.shutdown();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }

    }
}
